package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.order.ClockData
import com.cheyun.netsalev3.bean.order.OrderDetail2
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1

class OrderDetailsRepository(var tid: Int, var id: Int) {
    /**
     * 获取详情
     */
    fun getData(ReturnData: KFunction1<@ParameterName(name = "item") OrderDetail2,  Unit>) {
        ApiClient.getInstance().getOrderDetail(tid,id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<OrderDetail2>>() {
                    override fun onSuccess(t: BaseResp<OrderDetail2>) {
                        t.data?.apply {
                            ReturnData(this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }

                })
    }

    fun getClockList(ReturnData: KFunction1<@ParameterName(name = "item") List<ClockData>,  Unit>){
        ApiClient.getInstance().getClockList(tid,id)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<ClockData>>>() {
                    override fun onSuccess(t: BaseResp<List<ClockData>>) {
                        t.data?.apply {
                            ReturnData(this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }

                })
    }

    fun addClock( nodeid: Int,
                  payment: String,
                  license: String,
                  operate: String,
                  moth: () -> Unit, fail:()->Unit){
        ApiClient.getInstance().addClock(tid,id,nodeid,payment,license,operate)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<ClockData>>>() {
                    override fun onSuccess(t: BaseResp<List<ClockData>>) {
                        moth()
                    }

                    override fun onError(ex: ApiException) {
                        fail()
                    }

                })
    }



}